package com.qianyu.project.service.handler;

import com.alibaba.fastjson.JSON;
import com.qianyu.project.core.annotation.FlowHandler;
import com.qianyu.project.core.bean.FormAudit;
import com.qianyu.project.core.context.handler.FlowFinishedHandler;
import com.qianyu.project.entity.ApplyProgressPayment;
import com.qianyu.project.entity.IncomeContract;
import com.qianyu.project.entity.ProgressPayment;
import com.qianyu.project.service.IProgressPaymentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
@FlowHandler("apply_progress_payment")
public class ProgressPaymentPostProcessor implements FlowFinishedHandler {
    @Autowired
    private IProgressPaymentService progressPaymentService;

    @Override
    public void postAllowHandle(String jsonForm, FormAudit formAudit) {
        this.commonUpdate(jsonForm, formAudit, "3");
    }

    @Override
    public void postRefuseHandle(String jsonForm, FormAudit formAudit) {
        this.commonUpdate(jsonForm, formAudit, "2");
    }

    private void commonUpdate(String jsonForm, FormAudit formAudit, String approveStatus) {
        ProgressPayment progressPayment = JSON.parseObject(jsonForm, ProgressPayment.class);
        progressPayment.setApproveStatus(Integer.valueOf(approveStatus));
        progressPaymentService.updateById(progressPayment);
    }
}
